﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package org.aswing {
    import org.aswing.util.*;

    public class ButtonGroup {

        protected var buttons:Array;
        private var selection:ButtonModel = null;

        public function ButtonGroup(){
            this.buttons = new Array();
        }
        public static function groupButtons(... _args):ButtonGroup{
            var _local3:AbstractButton;
            var _local2:ButtonGroup = new (ButtonGroup)();
            for each (_local3 in _args) {
                _local2.append(_local3);
            };
            return (_local2);
        }

        public function append(_arg1:AbstractButton):void{
            if (_arg1 == null){
                return;
            };
            this.buttons.push(_arg1);
            if (_arg1.isSelected()){
                if (this.selection == null){
                    this.selection = _arg1.getModel();
                } else {
                    _arg1.setSelected(false);
                };
            };
            _arg1.getModel().setGroup(this);
        }
        public function appendAll(... _args):void{
            var _local2:AbstractButton;
            for each (_local2 in _args) {
                this.append(_local2);
            };
        }
        public function remove(_arg1:AbstractButton):void{
            if (_arg1 == null){
                return;
            };
            ArrayUtils.removeFromArray(this.buttons, _arg1);
            if (_arg1.getModel() == this.selection){
                this.selection = null;
            };
            _arg1.getModel().setGroup(null);
        }
        public function contains(_arg1:AbstractButton):Boolean{
            var _local2:Number = 0;
            while (_local2 < this.buttons.length) {
                if (this.buttons[_local2] == _arg1){
                    return (true);
                };
                _local2++;
            };
            return (false);
        }
        public function getElements():Array{
            return (ArrayUtils.cloneArray(this.buttons));
        }
        public function getSelection():ButtonModel{
            return (this.selection);
        }
        public function getSelectedButton():AbstractButton{
            var _local1:AbstractButton;
            for each (_local1 in this.buttons) {
                if (_local1.isSelected()){
                    return (_local1);
                };
            };
            return (null);
        }
        public function setSelected(_arg1:ButtonModel, _arg2:Boolean):void{
            var _local3:ButtonModel;
            if (((((_arg2) && (!((_arg1 == null))))) && (!((_arg1 == this.selection))))){
                _local3 = this.selection;
                this.selection = _arg1;
                if (_local3 != null){
                    _local3.setSelected(false);
                };
                _arg1.setSelected(true);
            };
        }
        public function isSelected(_arg1:ButtonModel):Boolean{
            return ((_arg1 == this.selection));
        }
        public function getButtonCount():Number{
            return (this.buttons.length);
        }

    }
}//package org.aswing 
